package com.ly.web.controller.erp;

import com.ly.common.annotation.Log;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.common.utils.StringUtils;
import com.ly.heart.domain.CustomerVisitRecordEntity;
import com.ly.heart.service.ICustomerVisitRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 客户拜访记录 前端控制器
 * </p>
 * @author WuZH
 * @since 2024-09-29
 */
@Api (value = "CustomerVisitRecord", tags = "客户拜访回访记录")
@RestController
@RequestMapping ("/heart/CustomerVisitRecord")
public class CustomerVisitRecordController {

    @Resource
    private ICustomerVisitRecordService iCustomerVisitRecordService;

    @PreAuthorize ("@ss.hasPermi('heart/CustomerVisitRecord:list')")
    @GetMapping ("/list")
    @ApiOperation ("查询客户拜访回访记录列表")
    public AjaxResult list (CustomerVisitRecordEntity customerVisitRecordEntity) {
        return iCustomerVisitRecordService.list ( customerVisitRecordEntity );
    }

    @PreAuthorize ("@ss.hasPermi('heart:CustomerVisitRecord:query')")
    @GetMapping (value = "/{id}")
    @ApiOperation ("查询客户拜访回访记录详情")
    public AjaxResult getInfo (@PathVariable ("id") String id) {
        CustomerVisitRecordEntity customerVisitRecordEntity = iCustomerVisitRecordService.querySingle ( id );
        return AjaxResult.success ( customerVisitRecordEntity );
    }

    @PreAuthorize ("@ss.hasPermi('heart:CustomerVisitRecord:add')")
    @Log (title = "新增客户拜访回访记录", businessType = BusinessType.INSERT)
    @PostMapping ("draft")
    @ApiOperation ("新增客户拜访回访记录")
    public AjaxResult draft (@RequestBody CustomerVisitRecordEntity customerVisitRecordEntity) {
        if ( StringUtils.isNotBlank ( customerVisitRecordEntity.getId () ) ) {
            return iCustomerVisitRecordService.updateSingle ( customerVisitRecordEntity );
        }
        return iCustomerVisitRecordService.draft ( customerVisitRecordEntity );
    }

    @PreAuthorize ("@ss.hasPermi('heart:CustomerVisitRecord:add')")
    @Log (title = "提交客户拜访回访记录", businessType = BusinessType.INSERT)
    @PostMapping ("submit")
    @ApiOperation ("提交客户拜访回访记录")
    public AjaxResult submit (@RequestBody CustomerVisitRecordEntity customerVisitRecordEntity) {
        return iCustomerVisitRecordService.submit ( customerVisitRecordEntity );
    }

    @PreAuthorize ("@ss.hasPermi('heart:CustomerVisitRecord:edit')")
    @Log (title = "修改客户拜访回访记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation ("修改客户拜访回访记录")
    public AjaxResult edit (@RequestBody CustomerVisitRecordEntity customerVisitRecordEntity) {
        return iCustomerVisitRecordService.updateSingle ( customerVisitRecordEntity );
    }

    @PreAuthorize ("@ss.hasPermi('heart:CustomerVisitRecord:remove')")
    @Log (title = "删除客户拜访回访记录", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{ids}")
    @ApiOperation ("删除客户拜访回访记录")
    public AjaxResult remove (@PathVariable String id) {
        return iCustomerVisitRecordService.deleteSingle ( id );
    }

}
